﻿using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.Reflection;
using System.IO;

namespace SerialPortToKeyboard
{
	[RunInstaller(true)]
	public class InstallerClass : System.Configuration.Install.Installer
	{
		public InstallerClass()
			: base()
		{
			this.Committed += new InstallEventHandler(MyInstaller_Committed);
		}

		private void MyInstaller_Committed(object sender, InstallEventArgs e)
		{
			try
			{
				string assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
				Process.Start(Path.Combine(assemblyDirectory, "SerialPortToKeyboard.exe"));
			}
			catch
			{}
		}

		public override void Install(IDictionary savedState)
		{
			base.Install(savedState);
		}

		public override void Commit(IDictionary savedState)
		{
			base.Commit(savedState);
		}

		public override void Rollback(IDictionary savedState)
		{
			base.Rollback(savedState);
		}
	}
}
